package http

import (
	"fmt"
	"gitee.com/Cauchy_AQ/gokv"
	myredis "gitee.com/Cauchy_AQ/gokv/redis"
)

var (
	db    *gokv.DB
	redis *myredis.RedisDataStruct
)

func init() {
	// 创建数据库引擎
	var err error
	opts := gokv.DefaultOptions
	db, err = gokv.Open(&opts)
	if err != nil {
		panic("failed to open db")
	}
	redis = myredis.InitialRedisDataStruct(db)
	if redis == nil {
		panic("failed to initial redis")
	}
}

// StartHTTPServer 启动 HTTP 服务
func StartHTTPServer(port uint16) error {
	r := SetupRouters()
	return r.Run(fmt.Sprintf(":%d", port))
}
